/**
 * 组件数据源属性mixins
 * <?  :dataSource="" />
 * @author xiufu.wang
 */
import dataSource from '../dataSource'
export default {
    mixins: [dataSource('selectDataSource', '', { multipleVm: true })],
    props: {
        //数据源
        dataSource: {},
        dataSourceKey: String,
    },
    created() {
        if (this.dataSource && !this.dataSource.isDataSource) {
            this.selectDataSource.updateOption(this.$attrs, this.dataSource)
        }
    },
    computed: {
        //原始数据
        realDataSource() {
            if (this.dataSource && !this.dataSource.isDataSource) {
                if (this.dataSourceKey) {
                    const nd = this.selectDataSource.clone(this.dataSourceKey)
                    nd.updateOption(this.$attrs, this.dataSource, true)
                    return nd
                }
                if (this.selectDataSource.target !== this.dataSource) { 
                    this.selectDataSource.updateOption(this.$attrs, this.dataSource, false)
                }
                return this.selectDataSource
            }
            return this.dataSource
        },
        selectDatas() {
            const datas = this.realDataSource && this.realDataSource.isDataSource ? this.realDataSource.formatDatas : this.realDataSource
            return datas;
        },
        //数据源状态
        isLoading() {
            return this.realDataSource && this.realDataSource.isDataSource === true ? this.realDataSource.loading : this.$attrs.loading
        }
    }
}